﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Fan.Dongping.Ali.Notepad.SL.NoteServiceRef;
using System.Collections.ObjectModel;
using Fan.Dongping.Ali.Notepad.SL.Utils;
using System.Windows.Browser;

namespace Fan.Dongping.Ali.Notepad.SL
{
    public partial class MainPage : UserControl
    {
        string userId = "0";//"20766253";
        long noteid = 1;
        public MainPage(string userId)
        {
            this.userId = userId;
            InitializeComponent();

        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            NoteServiceClient client = Common.GetClient();
            client.GetNoteCompleted += new EventHandler<GetNoteCompletedEventArgs>(client_GetNoteCompleted);
            client.GetNoteAsync(noteid);

            client.GetAllNotesByUserCompleted += new EventHandler<GetAllNotesByUserCompletedEventArgs>(client_GetAllNotesByUserCompleted);
            client.GetAllNotesByUserAsync(userId);

        }

        void client_GetAllNotesByUserCompleted(object sender, GetAllNotesByUserCompletedEventArgs e)
        {
            ObservableCollection<NoteSummary> ns = e.Result;
            DataGridNotes.ItemsSource = ns;
        }

        void client_GetNoteCompleted(object sender, GetNoteCompletedEventArgs e)
        {
            NoteSummary ns = e.Result;
            DataGridNotes.Tag = ns;
        }

        private void buttonAddNote_Click(object sender, RoutedEventArgs e)
        {
            Uri u = new Uri("http://localhost:3624/MainForm.aspx?P=AddNote");
            HtmlPage.Window.Navigate(u);
        }


    }
}
